//
//  GuideViewController.m
//  ToYourHeartNews
//
//  Created by XJing on 16/1/29.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥. All rights reserved.
//

#import "GuideViewController.h"
#import "LunBoTu.h"
#import "AppDelegate.h"
#import "NewsViewController.h"
@interface GuideViewController ()<UIScrollViewDelegate>
@property (nonatomic, assign)BOOL isOut;
@end

@implementation GuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //添加照片
    NSArray *arr = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", nil ];
    
    //引导页图片数组
    UIScrollView *scr = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    scr.contentSize = CGSizeMake(self.view.frame.size.width * (arr.count + 1), self.view.frame.size.height);
    scr.pagingEnabled = YES;
    scr.delegate = self;
    [self.view addSubview:scr];
    for (NSInteger i = 0; i < arr.count; i++) {
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(i * self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
        imgView.image = [UIImage imageNamed:arr[i]];
        [scr addSubview:imgView];
        [imgView release];
    }
    [scr release];

}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.x > 1 * self.view.frame.size.width + 20) {
        _isOut = YES;
    }
}
#pragma mark - 结束减速跳转主页
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    AppDelegate *app = [[UIApplication sharedApplication] delegate];
    
    if (_isOut) {
        [UIView animateWithDuration:1.5 animations:^{
            scrollView.alpha = 0;
        } completion:^(BOOL finished) {
            [scrollView removeFromSuperview];
#pragma mark - 修改window的跟视图
            app.window.rootViewController = app.tabBar;
            [self presentViewController:[[NewsViewController alloc]init] animated:YES completion:^{
                
            }];
        }];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
